package com.seal.yoyoshop.adminweb;

import com.seal.yoyoshop.bin.Order;
import com.seal.yoyoshop.service.OrderService;
import com.seal.yoyoshop.service.impl.OrderServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "OrderOperateServlet", value = "/admin/orderOperate")
public class OrderOperateServlet extends HttpServlet {

    private OrderService orderService = new OrderServiceImpl();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String operate = request.getParameter("operate");
        String idstr = request.getParameter("id");
        Integer id = Integer.parseInt(idstr);
        String statusstr = request.getParameter("status");
        Integer status = Integer.parseInt(statusstr);

        Order order = orderService.getOrderById(id);

        switch (operate){
            case "send":
                order.setStatus(3);
                break;
            case "finish":
                order.setStatus(4);
                break;
            case "delete":
                order.setStatus(0);
                break;
        }
        orderService.updateOrder(order);

        response.sendRedirect("orderList?status="+ status +"&page=1&10size=16");
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
